package game.players.goalkeeper.opp;


import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.appearances.Animation;
import com.uqbar.vainilla.appearances.Appearance;
import com.uqbar.vainilla.appearances.Sprite;

import game.ball.Possessed;
import game.ball.SoccerBall;
import game.players.SoccerPlayer;
import game.players.goalkeeper.GoalkeeperState;

public class ReturningToTheArcOppGoalkeeper extends GoalkeeperState {
	
	private Appearance appearance = new Animation(0.3,
			Sprite.fromImage("/images/arquero_arco.png").crop(21,11,84,77),
			Sprite.fromImage("/images/arquero_arco.png").crop(112,13,84,77),
			Sprite.fromImage("/images/arquero_arco.png").crop(200,13,84,79));

	public ReturningToTheArcOppGoalkeeper(SoccerPlayer player) {
		super(player);
		player.setAppearance(this.appearance);
	}
	
	public ReturningToTheArcOppGoalkeeper(SoccerPlayer player,boolean b) {
		super(player);
		this.setHasBall(b);
		player.setAppearance(this.appearance);
	}

	@Override
	public void update(DeltaState deltaState) {
		this.advanceToArc();
		if(this.collidesAgainstBall() && !this.getGoalkeeper().isMisplaced() && !this.hasBall()){
			this.setHasBall(true);
			SoccerBall ball = this.getGoalkeeper().getScene().getSoccerBall();
			if(!ball.isFree()){
				ball.getPlayer().loseTheBall();
				ball.setState(new Possessed(this.getGoalkeeper()));
			}
		}
		if(this.getGoalkeeper().isAccommodated()){
			if(this.hasBall())
				this.getGoalkeeper().setState(new GoalkeeperWithBallOpp(this.getGoalkeeper()));
			else
				this.getGoalkeeper().setState(new GoalkeeperWithoutBallOpp(this.getGoalkeeper()));
		}
	}

	@Override
	public boolean isWithBall() {
		return this.hasBall();
	}

	@Override
	public boolean isRight() {
		return false;
	}

}
